
const ws = require('nodejs-websocket');
console.log('开始建立连接...');


ws.createServer(function (conn) {
  conn.on("text", function (str) {
    console.log("收到的信息>>>" + str)
    str = JSON.parse(str);
    if (str.name === 'user') {
      conn.sendText(str.msg)
    }
  })
  conn.on("close", function (code, reason) {
    console.log("关闭>>>", reason)
  })
}).listen(8001)

console.log("WebSocket建立完毕")